<?php

/*
 * ************************************************* 
 * Created on :2012-3-20 8:15:40
 * Encoding   :UTF-8
 * Description:
 * 
 * @Author @lqs <soso2501@gmail.com>
 * @WAP_WEIBO (C)1996-2099 SINA Inc. 
 * ************************************************
 */

class Controller {

    var $tpl;
    var $template_dir;
    var $user;
    var $selfc; //目前的控制器名

    public function __construct() {
        $this->tpl = $GLOBALS['tpl'];
        $this->tpl->template_dir = SMARTY_TEMPLATE_DIR;
        $this->tpl->compile_dir = SMARTY_COMPILE_DIR;
        $this->tpl->cache_dir = SMARTY_CACHE_DIR;
        $this->user = $GLOBALS['user'];
        $this->tpl->assign("user", $this->user);
        $this->selfc = "main";
        $this->tpl->assign("sessionid", session_id());

        $this->init();
    }

    public function init() {
        
    }

    public function __call($f, $p) {
        if (method_exists($this, $f)) {
            $this->$f();
        }else
            throw new LException("action not find($f)");
    }

    /**
     * 如果处理的action是新闻类的话
     * 调用这个函数处理
     * @param type $type 标识哪一类的新闻 
     */
    public function _news($type) {
        $this->tpl->assign("selfaname", $type);
        if (!empty($_GET['id'])) {
            $n = News::byid($_GET['id']);
            if ($n['newstype'] == $type) {
                //处理单条新闻
                $this->_sinalnews($n);
                return;
            }
        }
        $newslist = News::bytype(array($type));
        Toolfunc::addnewslink($newslist);
        $this->tpl->assign("newslist", $newslist);
        $this->tpl->assign("module", "newslist");
        $this->tpl->display("include/mainfw.html");
    }

    /**
     * 将要显示的单条新闻数据加进来
     * 是比_news更底层的方法
     * @param type $n 至少要newstype,title,content这三个。可选为createdate
     */
    public function _sinalnews($n) {
        $this->tpl->assign("selfaname", $n['newstype']);
        $this->tpl->assign("news", $n);
        $this->tpl->assign("module", "newssingle");
        $this->tpl->display("include/mainfw.html");
    }

    /**
     * 处理文案类的显示
     * @param type $title 
     */
    public function _copy($title) {
        $r = Copy::get($title);
        $this->_sinalnews(array("newstype" => $title,
            "title" => $title,
            "content" => $r['content'],
            "createtime" => ''));
    }

}

/* End of file controller */


